﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace log4netTest
{
    public partial class Form1 : Form
    {
        private log4net.ILog log = log4net.LogManager.GetLogger("main");//这里算是一个用户标签
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            log.Info("系统启动！");
            /*
             ALL   全开
          DEBUG 
          INFO  如果级别为INFO，即ALL、DEBUG不显示
          WARN 
          ERROR 
          FATAL 
          OFF  全关
             */
            log.Debug("Debug");
            log.Info("Info");
            log.Warn("Warn");
            log.Error("Error");
            log.Fatal("Fatal");

        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            log.Info("系统正在退出！");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            log.Info("按键按下！");

            try { int i = Convert.ToInt32("A2"); } catch { log.Error("计算异常！"); }
        }
    }
}
